#define _CRT_SECURE_NO_WARNINGS
#include "game.h"
void InitBoard(char arr[ROWS][COLS], int rows, int cols, char set)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < cols; j++)
		{
			arr[i][j] = set;
		}
	}
}
void ShowBoard(char arr[ROWS][COLS], int row, int col)
{
	int i = 0;
	int j = 0;
	for (j = 0; j <= col; j++)
	{
		printf("%d ", j);
	}
	printf("\n");
	for (i = 1; i <= row; i++)
	{
		printf("%d ", i);
		for (j = 1; j <= col; j++)
		{
			printf("%c ", arr[i][j]);
		}
		printf("\n");
	}
}
void SetMine(char arr[ROWS][COLS], int row, int col, int count)
{
	int i = 0;
	int j = 0;
	while (count)
	{
		i = rand() % 9 + 1;
		j = rand() % 9 + 1;
		if (arr[i][j] == '0')
		{
			arr[i][j] = '1';
			count--;
		}

	}
}
void CNT(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y, int count[1])
{
	if (show[x][y] == '*' && (1 <= x) && (x <= 9) && (1 <= y) && (y <= 9))
	{
		int num = 0;
		num = mine[x - 1][y - 1] + mine[x - 1][y] + mine[x - 1][y + 1] +
			mine[x][y - 1] + mine[x][y + 1] +
			mine[x + 1][y - 1] + mine[x + 1][y] + mine[x + 1][y + 1] - 8 * '0';
		show[x][y] = num + '0';
		count[0] -= 1;
		if (show[x][y] == '0')
		{
			CNT(mine, show, x - 1, y - 1, count);
			CNT(mine, show, x, y - 1, count);
			CNT(mine, show, x + 1, y - 1, count);
			CNT(mine, show, x - 1, y, count);
			CNT(mine, show, x + 1, y, count);
			CNT(mine, show, x - 1, y + 1, count);
			CNT(mine, show, x, y + 1, count);
			CNT(mine, show, x + 1, y + 1, count);
		}
	}
}